package com.yqg.education.service.impl;

import com.yqg.education.entity.TeachPlan;
import com.yqg.education.mapper.TeachPlanMapper;
import com.yqg.education.service.ITeachPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yqg.education.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TeachPlanServiceImpl 服务实现类
 * @author 张芸博
 * @since 2025-04-10
 */
@Service
public class TeachPlanServiceImpl extends ServiceImpl<TeachPlanMapper, TeachPlan> implements ITeachPlanService {
    @Resource
    private IUserService userService;
    @Resource
    private TeachPlanMapper teachPlanMapper;

    @Override
    public Map<String, Object> findResourcePage(Integer pageNum, Integer pageSize, String name, Integer typeId, Integer userId, Integer courseId) {
        Integer pageStartNumber = pageNum * pageSize - pageSize;
        List<Long> courseIds = null;
        //App端courseId为空，网页端不为空
        if (courseId == null){
            //获取学员对应所在班级的课程ID
            courseIds =  userService.getCourseIdByUserId(userId);
        }
        //获取资源并返回
        List<TeachPlan> resourceList = teachPlanMapper.findResourcePage(pageStartNumber,pageSize,name,typeId,courseIds,userId,courseId);
        Integer count = teachPlanMapper.findResourcePageCount(name,typeId,courseIds,userId,courseId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("records", resourceList);
        map.put("total", count);
        return map;
    }
}
